<?php
/** Copyright 2014 TinPhp Systems, Inc.
 * @author zhangxilian 2013-8-15
 */
if (!defined('IN_TINPHP')) {
	exit ('Access Denied');
}

/**
 * 管理员帐号业务逻辑类
 * 
 * 每个 Logic 对应一个业务逻辑处理单元、必须继承自 BaseLogic
 * 每个 Logic 对应一个或多个 View/DAO
 */
class CommentLogic extends TinBaseLogic {

	private $userDAO;
	private $userTypeDAO;

	// 每个 Logic 需要有一个构造函数
	public function CommentLogic() {        
		parent::__construct();
		$this->logger->className = "CommentLogic";
		$this->commentDAO = Tin::getDAO("AssignTable","COMMENT");
	}
	
	public function __destruct(){
		$this->commentDAO = null;
	}
//=========================================用户=============================================================
	/** 指定获取单条用户记录
	 * @author ZhangXiLian 2014-8-29 */
	public function getCommentItem($cols, $cond, $params = false){
		return $this->commentDAO->selectRowByCond($cols, $cond, $params);
	}
	/** 根据指定条件分页获取用户列表数据 
	 * @author ZhangXiLian 2014-8-29 */
	public function getCommentList($cols, $cond, $order_by  = null, $page = null, $size = null){
        $res = array();
		$res["data"] = $this->commentDAO->selectByCond($cols, $cond . " " . $order_by, $page, $size);
		if ($page){
			$res["count"] = $this->commentDAO->getCountByCond($cond);
		}
		return $res;
	}
	/** 添加用户记录
	 * @author ZhangXiLian 2014-8-29 */
	public function addComment($data){		
		$map = Tin :: createDataMap();
		if($data['datatype']) $map->addEntry('DATATYPE', $data['datatype'], DB::INT);
		if($data['dataid']) $map->addEntry('DATAID', $data['dataid'], DB::INT);
		if($data['comment']) $map->addEntry('COMMENT', $data['comment'], DB::TEXT);
		if($data['parentid']) $map->addEntry('PARENTID', $data['parentid'], DB::INT);
		if($data['userid']) $map->addEntry('USERID', $data['userid'], DB::INT);
		$map->addEntry('STATE', 1, DB::INT);
                $map->addEntry('CREATE_TIME', 'now()', DB::DATETIME);
		try{
                    $newID = $this->commentDAO->insert($map, false, true);				
                    return $newID;
		}catch(Exception $e){
                    $this->logger->error("addComment:".$e->getMessage());
                    echo $e->getMessage();
                    return false;
		}
	}
	/** 根据指定条件更新记录
	 * @author ZhangXiLian 2014-8-29 */
	public function updateUserByCond($data, $cond){
		try{
            $map = Tin :: createDataMap();
            //$map->addEntry('USERNAME', $data['username'], DB::VARCHAR);
			$map->addEntry('PASSWORD', $data['password'], DB::VARCHAR);
			$map->addEntry('EMAIL', $data['email'], DB::VARCHAR);
			$map->addEntry('IDCARDS', $data['idcards'], DB::VARCHAR);
			$map->addEntry('INVITE_TOTAL', $data['invite_total'], DB::INT);
			$map->addEntry('PAY_PASSWORD', $data['pay_password'], DB::VARCHAR);
			$map->addEntry('PHONE', $data['phone'], DB::VARCHAR);
			$map->addEntry('REALNAME', $data['realname'], DB::VARCHAR);

			//$map->addEntry('PARENT_ID', $data['parent_id'], DB::INT);
            $res = $this->userDAO->updateByCond($map, $cond, false);
            
            return $res;
        } catch(Exception $e){
            $this->logger->error("updateUserByCond:".$e->getMessage());
            return false;
        }
	}
	/** 根据条件更新指定字段
	 * @param array $dataArr 要更新的字段值数组
	 * @param string $cond 条件
	 * @param array $params 绑定变量
	 * @author ZhangXiLian 2014-8-29 */
	public function updateFieldVal($dataArr, $cond, $params=false){
		if(!is_array($dataArr))return false;
		$map = Tin :: createDataMap();
		foreach ($dataArr as $k=>$v){
			$map->addEntry(strtoupper($k), $v, DB::INT);
		}
		return $this->userDAO->updateByCond($map, $cond, false, $params);
	}
//=========================================用户类型角色=============================================================
	/** 指定获取单条用户记录
	 * @author ZhangXiLian 2014-8-29 */
	public function getUserTypeItem($cols, $cond, $params = false){
		return $this->userTypeDAO->selectRowByCond($cols, $cond, $params);
	}

	
}//End Class
?>
